package com.quasar.hpatient.view;

import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import com.quasar.hpatient.R;
import com.quasar.hpatient.base.BaseActivity;
import com.quasar.hpatient.network.ApiService;
import com.quasar.hpatient.network.RetrofitConnection;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.ViewById;


@EActivity(R.layout.activity_browser)
public class WebActivity extends BaseActivity {
    @ViewById(R.id.webView1)
    WebView mwv;
    @Extra
    String url;

    @ViewById(R.id.progressBar1)
    ProgressBar mjdpb;


    @AfterViews
    void init(){
        initView();
        initOnClik();
        initWebView();
        initData();
    }

    @Override
    protected void initView() {
        initToolbar();
    }

    @Override
    protected void initData() {
        mwv.loadUrl(ApiService.ConsultationDetails+url);
    }

    private void initOnClik() {
        // WebView........
        mwv.setWebViewClient(new WebViewClient() {
            @Override
            //网页加载完成
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                mjdpb.setVisibility(View.GONE);
                super.onPageFinished(view, url);
            }

            // 网页加载失败，重新加载
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                mwv.loadUrl(url);
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
    }
    private void initWebView() {
        // TODO Auto-generated method stub
        WebSettings webSettings = mwv.getSettings();
        webSettings.setJavaScriptEnabled(true); //支持 js
        //webSettings.setPluginsEnabled(true); //支持插件
        webSettings.setUseWideViewPort(false); //将图片调整到适合 webview 的大小
        webSettings.setSupportZoom(true); //支持缩放
        webSettings.supportMultipleWindows(); //多窗口
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭 webview 中缓存
        webSettings.setAllowFileAccess(true); //设置可以访问文件
        webSettings.setNeedInitialFocus(true); //当 webview 调用 requestFocus 时为 webview 设置节点
        webSettings.setBuiltInZoomControls(true); //设置支持缩放
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过 JS 打开新窗口
        webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
        webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
    }


}
